﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_attendance
	/// </summary>
	public partial class oa_attendance
	{
		public oa_attendance()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("attendance_id", "oa_attendance"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int attendance_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_attendance");
			strSql.Append(" where attendance_id=@attendance_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@attendance_id", MySqlDbType.Int32)
};
			parameters[0].Value = attendance_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_attendance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_attendance(");
			strSql.Append("person_id,attendance_type,attendance_date,note,date_length)");
			strSql.Append(" values (");
			strSql.Append("@person_id,@attendance_type,@attendance_date,@note,@date_length)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@attendance_type", MySqlDbType.Int32,11),
					new MySqlParameter("@attendance_date", MySqlDbType.DateTime),
					new MySqlParameter("@note", MySqlDbType.VarChar,64),
					new MySqlParameter("@date_length", MySqlDbType.Decimal,4)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.attendance_type;
			parameters[2].Value = model.attendance_date;
			parameters[3].Value = model.note;
			parameters[4].Value = model.date_length;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_attendance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_attendance set ");
			strSql.Append("person_id=@person_id,");
			strSql.Append("attendance_type=@attendance_type,");
			strSql.Append("attendance_date=@attendance_date,");
			strSql.Append("note=@note,");
			strSql.Append("date_length=@date_length");
			strSql.Append(" where attendance_id=@attendance_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@attendance_type", MySqlDbType.Int32,11),
					new MySqlParameter("@attendance_date", MySqlDbType.DateTime),
					new MySqlParameter("@note", MySqlDbType.VarChar,64),
					new MySqlParameter("@date_length", MySqlDbType.Decimal,4),
					new MySqlParameter("@attendance_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.attendance_type;
			parameters[2].Value = model.attendance_date;
			parameters[3].Value = model.note;
			parameters[4].Value = model.date_length;
			parameters[5].Value = model.attendance_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int attendance_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_attendance ");
			strSql.Append(" where attendance_id=@attendance_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@attendance_id", MySqlDbType.Int32)
};
			parameters[0].Value = attendance_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string attendance_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_attendance ");
			strSql.Append(" where attendance_id in ("+attendance_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_attendance GetModel(int attendance_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select attendance_id,person_id,attendance_type,attendance_date,note,date_length from oa_attendance ");
			strSql.Append(" where attendance_id=@attendance_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@attendance_id", MySqlDbType.Int32)
};
			parameters[0].Value = attendance_id;

			becom.Model.oa_attendance model=new becom.Model.oa_attendance();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["attendance_id"]!=null && ds.Tables[0].Rows[0]["attendance_id"].ToString()!="")
				{
					model.attendance_id=int.Parse(ds.Tables[0].Rows[0]["attendance_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["person_id"]!=null && ds.Tables[0].Rows[0]["person_id"].ToString()!="")
				{
					model.person_id=int.Parse(ds.Tables[0].Rows[0]["person_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["attendance_type"]!=null && ds.Tables[0].Rows[0]["attendance_type"].ToString()!="")
				{
					model.attendance_type=int.Parse(ds.Tables[0].Rows[0]["attendance_type"].ToString());
				}
				if(ds.Tables[0].Rows[0]["attendance_date"]!=null && ds.Tables[0].Rows[0]["attendance_date"].ToString()!="")
				{
					model.attendance_date=DateTime.Parse(ds.Tables[0].Rows[0]["attendance_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["note"]!=null && ds.Tables[0].Rows[0]["note"].ToString()!="")
				{
					model.note=ds.Tables[0].Rows[0]["note"].ToString();
				}
				if(ds.Tables[0].Rows[0]["date_length"]!=null && ds.Tables[0].Rows[0]["date_length"].ToString()!="")
				{
					model.date_length=decimal.Parse(ds.Tables[0].Rows[0]["date_length"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select attendance_id,person_id,attendance_type,attendance_date,note,date_length ");
			strSql.Append(" FROM oa_attendance ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_attendance";
			parameters[1].Value = "attendance_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

